// start layer
var g_startLayer = null;
var StartLayer = cc.Layer.extend({
    ///////////// constructor ///////////////////
    ctor:function () {
        // super init first
        this._super();
        g_startLayer=this;
        // add canvas
        this.addCanvas();
        // add menu
        this.AddMenu();

        var filename = AudioResource("start.mp3");
        cc.audioEngine.playMusic(filename,true);
    },
    addCanvas : function(){
        var filename = StartResource("canvas.jpg");
        var background = new cc.Sprite(filename);
        background.setPosition( cc.p(cc.winSize.width/2,cc.winSize.height/2) );
        this.addChild(background);
    },
    AddMenu : function(){
        var filename = StartResource("begin0.png");
        var filename1 = StartResource("begin1.png");
        var begin = new cc.MenuItemImage(filename,filename1,this.onBeginMenu , this);
        begin.setPosition( cc.p(cc.winSize.width/2,100) );
        var menu = cc.Menu.create( begin );
        menu.setPosition(cc.p(0,0));
        this.addChild( menu );
    },
    onBeginMenu : function(sender){
        cc.audioEngine.stopMusic();
        Loading.preload(m_resources, function () {
            cc.director.runScene(new MainScene());
        }, this);
    }
});
AddStartLayer=function(parent){
    if(parent){
        var layer = new StartLayer();
        parent.addChild( layer );
        cc.log("*** add start layer down");
    }else{
        cc.log("*** invalid parent");
    }
}
RemoveStartLayer=function(clear){
    if(g_startLayer){
        g_startLayer.removeFromParent(clear);
        cc.log("*** remove start layer down, clear: "+clear);
    }else{
        cc.log("g_startLayer is invalid");
    }
}